package com.daiziru.learning.juc;

import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;

import static sun.misc.PostVMInitHook.run;

/**
 * @author: daiziru
 * @createDate: 2024/12/5 15:16
 */
public class ThreadTest {

    public static void main(String[] args) {

        new Thread(() -> {
            System.out.println("这是第一个线程");

        }).start();

        Thread thread0 = new Thread("线程0"){
            public void run() {
                System.out.println("测试休眠");
                try {
                    Thread.sleep(3000);
                    TimeUnit.SECONDS.sleep(3);
                    TimeUnit.MINUTES.sleep(3);
                } catch (InterruptedException e) {
                    System.out.println(this.getName() + "休眠被打断了");
                    throw new RuntimeException(e);
                }

            }
        };
        thread0.start();
        //打断休眠
        thread0.interrupt();
        String name = thread0.getName();

        Runnable runnable = ThreadTest::runMethod;
        Thread thread1 = new Thread(runnable, "测试线程");
        thread1.start();


        FutureTask<Integer> futureTask = new FutureTask<>(() -> {
            System.out.println("aaa");
            return 100;
        });
        new Thread(futureTask, "测试线程3").start();

    }

    private static void runMethod() {
        System.out.println("这是一个测试线程");
    }
}
